// components/custom-activity-tags/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        option: {
            type: Array,
            value: []
        }
    },

    observers: {
        // 监听弹出层开启、关闭状态变更
        "option": function (e) {
            const arr = e.map(item=>{
                return {
                    ...item,
                    title: this.parseTtile(item)
                }
            })
            this.setData({
                activeList: arr
            })
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        activeList: []
    },

    /**
     * 组件的方法列表
     */
    methods: {
        parseTtile(value) {
            let actstr = ""
            value.buy = value.buy.replaceAll(".00", "")
            value.derate = value.derate.replaceAll(".00", "")
            // 满额活动(type:1,2,5,6) buy <=0 或者 满件活动(type:3,4) buy
            switch (value.type) {
                case "1":
                    if(value.type<=0){
                        actstr = `立减${value.derate}元`
                    }else{
                        actstr = `满${value.buy}元减${value.derate}元`
                    }
                    break
                case "2":
                    if(value.type<=0){
                        actstr =  `送${value.derate}件`
                    }else{
                        actstr =  `满${value.buy}元送${value.derate}件`
                    }
                    break
                case "3":
                    actstr = `${value.buy}送${value.derate}`
                    break
                case "4":
                    if(value.type<=0){
                        actstr = `${value.derate / 10}折`
                    }else{
                        if(value.buy == 1) {
                            actstr = `${value.derate / 10}折`
                        } else {
                            actstr = `${value.buy}件${value.derate / 10}折`
                        }
                       
                        //
                    }
                    break
                case "5":
                    if(value.type<=0){
                        actstr = `${value.derate / 10}折`
                    }else{
                        actstr = `满${value.buy}元打${value.derate / 10}折`
                    }
                    break
                case "6":
                    if(value.type<=0){
                        actstr = `立减${value.derate}元`
                    }else{
                        actstr = `满${value.buy}送${value.derate}`
                    }
                    break
                default:
                    break
            }
            return actstr
        },
    }
})
